package com.visikard.asynctask;

import android.os.Handler;
import android.os.Message;

import com.visikard.application.UIMessage;
import com.visikard.business.CouponBusManage;
import com.visikard.response.BaseResponse;
import com.visikard.response.GetListCouponResponse;

public class GetListCouponTask extends BaseTask {

	public static final int POS_USERID = 0;
	public static final int POS_TIMEZONE = 1;
	public static final int POS_PAGEINDEX = 2;
	public static final int POS_PAGESIZE = 3;

	public GetListCouponTask(Handler handler) {
		super(handler);

	}

	public GetListCouponTask(Handler handler, boolean isShowProgress) {
		super(handler, isShowProgress);

	}

	@Override
	protected Object doBackgroundWork(Object... params) {
		String userId = (String) params[POS_USERID];
		String timeZone = (String) params[POS_TIMEZONE];
		String pageIndex = (String) params[POS_PAGEINDEX];
		String pageSize = (String) params[POS_PAGESIZE];
		CouponBusManage busObj = new CouponBusManage();
		return busObj.getListCoupon(userId, timeZone, pageIndex, pageSize);
	}

	@Override
	protected boolean handleResult(Object result) {

		GetListCouponResponse response = (GetListCouponResponse) result;
		if (response != null) {
			switch (response.getErrorCode()) {
				case BaseResponse.SUCCESS:
					Message successMsg = new Message();
					successMsg.what = UIMessage.MSG_GET_LIST_COUPON_FINISH;
					successMsg.obj = result;
					mUIHandler.sendMessage(successMsg);
			}

		}
		return false;
	}
}
